<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>我的</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../plugins/mui/mui.min.css">
		<script src="../../js/statistics.js"></script>
		<style type="text/css">
			* {
				box-sizing: border-box;
				font-family: 'Microsoft YaHei';

			}
			body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, form, input, p, table, th, td, select, option {
				padding: 0;
				margin: 0;
				list-style: none;
			}
			body {}
			/*title的样式覆盖*/
			.mui-bar {
				background-color: #43ac45;
			}
			.mui-title {
				color: #fff;
			}
			/*列表数字角标移动防止盖住右箭头*/
			.mui-table-view-cell>.mui-badge {
				right: 10.6%;
			}
			.mui-table-view {
				margin-top: 10px;
			}
			.mui-navigate-right {
				line-height: 22px;
				font-size: 15px;
			}
			.icon1 {
				width: 21px;
				height: 21px;
				float: left;
				margin-right: 2.66%;
				/*vertical-align: middle;*/
				display: block;
			}
			.mui-badge-red {
				background-color: #ef113a;
			}
			.icon2>li>a>img {
				width: 59px;
				height: 59px;
				margin-right: 7.4%;
			}
			.icon2>li>a {
				line-height: 59px;
				font-size: 16px;
			}
			.icon2>li>a>div {
				display: inline-block;
				line-height: 16px;
				float: left;
				margin-top: 11px;
			}
			.icon2>li>a>div>span {
				display: inline-block;
			}
			.icon2>li>a>div>span:last-child {
				color: #999;
				font-size: 14px;
				line-height: 14px;
			}
			.icon2>li>span {
				position: absolute;
				top: 50%;
				right: 13.3%;
				-webkit-transform: translateY(-50%);
				width: 26px;
				height: 26px;
				background: url('../../images/my/index/erweima.png') no-repeat center center;
				background-size: cover;
			}
			.mui-table-view:before {
				display: none;
			}
			.mui-table-view:after {
				display: none;
			}
			.mui-table-view-cell:after {
				background-color: #e5e5e5;
			}
			/*百分比优化*/
			.mui-table-view-cell {
				padding: 11px 4%;
			}
			.mui-table-view-cell>a:not(.mui-btn) {
				margin: -11px -4%;
			}
			.mui-navigate-right:after,
			.mui-push-right:after {
				right: 4%;
			}
			#user-nicheng {
				padding-right: 20px;
				background: url('') no-repeat top right;
				background-size: 14px 14px;
			}
			.man {
				background-image: url('../../images/my/index/man.png')!important;
			}
			.woman {
				background-image: url('../../images/my/index/woman.png')!important;
			}
		</style>
	</head>

	<body>
		<ul class="mui-table-view icon2">
			<li class="mui-table-view-cell">
				<a class="mui-navigate-right" id='user'>
					<img src="../../images/my/index/gray.png" alt="" class='icon1' id='mainImage'>
					<div>
						<span style='margin-bottom:5px;' id='user-nicheng'></span><br/>
						<span id='cg_username'>用户名：</span>
					</div>
				</a>
				<span id='erweima'></span>
				<!--<span class="mui-badge mui-badge-red">11</span>-->
			</li>
		</ul>

		<ul class="mui-table-view">
			<li class="mui-table-view-cell" id='post1'>
				<a class="mui-navigate-right">
					<img src="../../images/my/index/1.png" alt="" class='icon1' />我的帖子
				</a>
				<!--<span class="mui-badge mui-badge-red">11</span>-->
			</li>

			<li class="mui-table-view-cell" id='comment1'>
				<a class="mui-navigate-right">
					<img src="../../images/my/index/3.png" alt="" class='icon1' /> 我评论的
				</a>
				<!--<span class="mui-badge mui-badge-red">11</span>-->
			</li>
			<li class="mui-table-view-cell" id="favorite">
				<a class="mui-navigate-right">
					<img src="../../images/my/index/5.png" alt="" class='icon1' /> 我的收藏
				</a>
				<!--<span class="mui-badge mui-badge-red">11</span>-->
			</li>
		</ul>

		<ul class="mui-table-view">
			<!--<li class="mui-table-view-cell" id="download1">-->
				<!--<a class="mui-navigate-right">-->
					<!--<img src="../../images/my/index/7.png" alt="" class='icon1' /> 推荐下载-->
				<!--</a>-->
				<!--&lt;!&ndash;<span class="mui-badge mui-badge-red">11</span>&ndash;&gt;-->
			<!--</li>-->
			<li class="mui-table-view-cell" id='seting'>
				<a class="mui-navigate-right">
					<img src="../../images/my/index/6.png" alt="" class='icon1' /> 设置
				</a>
				<!--<span class="mui-badge mui-badge-red">11</span>-->
			</li>
		</ul>
		
		<script src="../../plugins/jquery/jquery-3.1.0.min.js"></script>
		<script src="../../plugins/mui/mui.min.js"></script>
		<!--<script type="text/javascript" src="../plugins/mui/update.js"></script>-->
		<script src="../../js/getApiToken.js"></script>
		<script src="../../js/md5.js"></script>
		<script type="text/javascript">
			mui.init({
//				statusBarBackground: '#43ac45', //ios下设置顶部背景色
			});
			mui.plusReady(function() {
				//关闭等待框
				plus.nativeUI.closeWaiting();
				//显示当前页面
				mui.currentWebview.show('slide-in-right',200);
				init();	
				//初始震动跟铃声的状态,个人信息
				function init() {
					//初始震动跟铃声的状态
					if(!plus.storage.getItem('shake')) {
						plus.storage.setItem('shake', 'on');
						plus.storage.setItem('tinkle', 'on');
					} else {

					}
					if(true){
						myAjax('personal/user_profile/getselfprofile', 'get', {
							'user_id': plus.storage.getItem('cg_user_id'),
							'user_token': plus.storage.getItem('cg_user_token')
						}, function(data) {
							if(!data.success){
								return ;//发生错误 就直接退出
							}
							//初始化头像

							//ios版本打开
//							plus.storage.setItem('cg_headimgurl', _baseUrl+data.data.headimgurl);
							//安卓打开下面
							download(data.data.headimgurl);
							//初始用户名
							plus.storage.setItem('cg_username', data.data.username+'');
							//初始用户名的性别
							plus.storage.setItem('cg_sex', data.data.sex+'');
							//初始昵称
							plus.storage.setItem('cg_nickname', data.data.nickname+'');
							//初始化个性签名
							plus.storage.setItem('cg_signature', data.data.signature);
							//初始化二维码
							plus.storage.setItem('cg_qrcode', data.data.qrcode+'');
							//初始实名认证
							plus.storage.setItem('cg_certification', data.certification+'');
							//初始化手机号码
							plus.storage.setItem('cg_mobile', data.data.mobile+'');
							//初始化邮箱
							plus.storage.setItem('cg_email', data.data.email);
							//初始城市
							if(!data.data.city){data.data.city='320000|江苏省|320400|常州市'}
							plus.storage.setItem('cg_city', data.data.city);
							//初始化地址
							plus.storage.setItem('cg_address', data.data.address);
							//初始化完成
							set();
						});
					}else{
						set();
					}
				}
				//图片下载函数
				function download(data){
					var data_path=data;
					plus.io.resolveLocalFileSystemURL("_doc/userImg/", function( entry ) {
						// 可通过entry对象操作test.html文件
						var directoryReader = entry.createReader();
						directoryReader.readEntries( function( entries ){
							for( var i=0; i < entries.length; i++ ) {
								entries[i].remove();//遍历每个文件
							}
							var dtask = plus.downloader.createDownload(_baseUrl+data_path, {filename:"_doc/userImg/"}, function(d,status){
								if ( status == 200 ) {
									plus.io.resolveLocalFileSystemURL(d.filename, function(entry) {
										entry.file( function ( file ) {
											plus.storage.setItem('cg_headimgurl', entry.toLocalURL());
											$('#mainImage')[0].src=plus.storage.getItem('cg_headimgurl');
										}, function ( e ) {
											alert( e.message );
										});
									});
								} else {
									plus.nativeUI.alert("头像下载失败！");
								}
							});
							dtask.start();
						}, function ( e ) {
							alert( "Read entries failed: " + e.message );
						} );


					}, function ( e ) {
						var dtask = plus.downloader.createDownload(_baseUrl+data_path, {filename:"_doc/userImg/"}, function(d,status){
							if ( status == 200 ) {
//											console.log(d.filename);
								plus.io.resolveLocalFileSystemURL(d.filename, function(entry) {
									entry.file( function ( file ) {
										plus.storage.setItem('cg_headimgurl', entry.toLocalURL());
										$('#mainImage')[0].src=plus.storage.getItem('cg_headimgurl');
									}, function ( e ) {
										alert( e.message );
									});
								});
							} else {
								plus.nativeUI.alert("头像下载失败！");
							}
						});
						dtask.start();
					} );
				}

				function set(){
					//设置头像
					var a=plus.storage.getItem('cg_headimgurl');
					if(a){
						$('#mainImage')[0].src=plus.storage.getItem('cg_headimgurl');
					}else{

					}
					//设置昵称
					if(plus.storage.getItem('cg_nickname')){
						$('#user-nicheng').html(plus.storage.getItem('cg_nickname'));
					}
					//设置用户名
					if(plus.storage.getItem('cg_username')){
						$('#cg_username').html('用户名：'+plus.storage.getItem('cg_username'));
					}
					//设置性别
					if((plus.storage.getItem('cg_sex')==0)||(plus.storage.getItem('cg_sex')==1)){
							$('#user-nicheng').addClass('man');
					}else{
							$('#user-nicheng').addClass('woman');
					}
				}
				
				var erweima = document.getElementById("erweima");
				//监听点击事件
				erweima.addEventListener("tap", function() {
					mui.openWindow({
						url: 'erweima.html',
						id: 'erweima.html',
						show: {
							autoShow: false, //页面loaded事件发生后自动显示，默认为true
							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});
				//个人信息
				var user = document.getElementById("user");
				user.addEventListener("tap", function() {
					mui.openWindow({
						url: 'user-0.html',
						id: 'user-0.html',
						show: {
							autoShow: false, //页面loaded事件发生后自动显示，默认为true
							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});

				//设置
				seting.addEventListener("tap", function() {
					mui.openWindow({
						url: 'seting.html',
						id: 'seting.html',
						show: {
							autoShow: false, //页面loaded事件发生后自动显示，默认为true
							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});
				//设置
//				var download1 = document.getElementById("download1");
//				download1.addEventListener("tap", function() {
//					mui.openWindow({
//						url: 'user-10.html',
//						id: 'user-10.html',
//						show: {
//							autoShow: false, //页面loaded事件发生后自动显示，默认为true
//							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
//						},
//						waiting: {
//							title: '正在加载...' //等待对话框上显示的提示内容
//						}
//					})
//				});
				//我的帖子
				post1.addEventListener("tap", function() {
					console.log('点击')
					mui.openWindow({
						url: 'post-1.html',
						id: 'post-1.html',
						show: {
//							autoShow: false, //页面loaded事件发生后自动显示，默认为true
//							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});
				//我的收藏
				favorite.addEventListener("tap", function() {
					mui.openWindow({
						url: 'favorite-1.html',
						id: 'favorite-1.html',
						show: {
							autoShow: false, //页面loaded事件发生后自动显示，默认为true
							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});
				//我的收藏
				comment1.addEventListener("tap", function() {
					mui.openWindow({
						url: 'comment-1.html',
						id: 'comment-1.html',
						show: {
							autoShow: false, //页面loaded事件发生后自动显示，默认为true
							duration: 200 //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						},
						waiting: {
							title: '正在加载...' //等待对话框上显示的提示内容
						}
					})
				});

				//动态接受数据进行处理
				window.addEventListener("pageflowrefresh", function(e) {
					//获得事件参数
					if(e.detail.userImg) {
						mui('#mainImage')[0].src = e.detail.userImg;
					} else if(e.detail.gender) {
						if(e.detail.gender==1){
			    			$('#user-nicheng').removeClass('man').removeClass('woman').addClass('man');
				    	}else{
				    		$('#user-nicheng').removeClass('man').removeClass('woman').addClass('woman');
				    	}
				    	if(plus.storage.getItem('cg_headimgurl')){
				    		$('#mainImage')[0].src=plus.storage.getItem('cg_headimgurl');
				    	}
					} else if(e.detail.userName) {
						mui('#user-nicheng')[0].innerHTML = e.detail.userName;
					}
				});

			});
		</script>
	</body>
</html>